package datatester;

import java.util.ArrayList;

import po.TeacherPO;
import teacherdata.Teacherdata;
import junit.framework.TestCase;

public class TeacherdataTester extends TestCase {
	Teacherdata td;

	public void testoutputByID() {
		TeacherPO po = new TeacherPO("testT01", "testLiu", "software");

		try {
			td = new Teacherdata();
			td.input(po);
			TeacherPO test = td.outputByID("testT01");
			String[] record = test.getData();
			assertTrue(record[1].equals("testLiu")
					&& record[2].equals("software"));
		} catch (Exception e) {
			assertTrue(false);
		}
	}

	public void testoutputByDep() {
		try {
			td = new Teacherdata();
			ArrayList<TeacherPO> test1 = td.outputByDep("no such dep");
			ArrayList<TeacherPO> test2 = td.outputByDep("software");
			assertTrue(test1.isEmpty() && (!test2.isEmpty()));
		} catch (Exception e) {
			assertTrue(false);
		}
	}

	public void testinput() {
		TeacherPO po = new TeacherPO("testT05", "testLiu", "software");
		try {
			td = new Teacherdata();
			td.input(po);
			TeacherPO getpo = td.outputByID("testT05");
			String[] record = getpo.getData();
			assertTrue(record[1].equals("testLiu")
					&& record[2].equals("software"));
		} catch (Exception e) {
			assertTrue(false);
		}
	}

	public void testupdate() {
		TeacherPO po1 = new TeacherPO("testT04", "testLiu", "software");
		TeacherPO po2 = new TeacherPO("testT04", "testQian", "math");
		try {
			td = new Teacherdata();
			td.input(po1);
			td.update(po2);
			TeacherPO getpo = td.outputByID("testT04");
			assertEquals(getpo.getData()[2], "math");
		} catch (Exception e) {
			assertTrue(false);
		}
	}
}
